// collections project collections.go
package collections

type List struct{
	data []interface{}
	size int
	capacity int
}

func NewList(capacity int) *List {
	data := make([]interface {}, capacity)
	list := &List{data, 0, capacity}
	return list
}

func (this *List) Add (item interface {}){

	this.ensureCapacity()

	this.data[this.size] = item

	this.size += 1
}

func (this *List) Remove(index int){

	for ; index < this.size; index += 1 {
		this.data[index] = this.data[index + 1]
	}

	this.data[index] = nil
	this.size -= 1
}

func (this *List) Get(index int) interface{}{
	return this.data[index]
}

func (this *List) ensureCapacity() {

	if(this.capacity > this.size){
		return
	}

	data := make([]interface{}, this.capacity * 2)

	for i, v := range this.data {
		  data[i] = v
	}

	this.data = data
}

func (this List) Size() int {
	return this.size
}
